package com.ulook.lookplanet.ui.home.modify;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.ulook.lookplanet.base.BaseViewModel2;
import com.ulook.lookplanet.common.AppServer;
import com.ulook.lookplanet.data.model.TUser;
import com.ulook.lookplanet.util.net.AsynRequestUtil;
import com.ulook.lookplanet.util.net.OkHttpException;
import com.ulook.lookplanet.util.net.RequestParams;
import com.ulook.lookplanet.util.net.ResponseCallback;

import java.io.File;
import java.util.List;

/**
 * 描述：
 *
 * @author L1998
 * @data 2021/5/14
 */
public class ModifyUserViewModel extends BaseViewModel2 {

    private int currUserId;
    private TUser user = new TUser();
    private List<File> images;
    private MutableLiveData<Boolean> state = new MutableLiveData<>();

    public LiveData<Boolean> getState(){
        return state;
    }

    public List<File> getImages() {
        return images;
    }

    public void setImage(List<File> images) {
        this.images = images;
    }

    public int getCurrUserId() {
        return currUserId;
    }

    public void setCurrUserId(int currUserId) {
        this.currUserId = currUserId;
    }

    public TUser getUser() {
        return user;
    }

    public void setUser(TUser user) {
        this.user = user;
    }

    /**
     * 提交
     */
    public void commit(){
        ResponseCallback callback = new ResponseCallback() {
            @Override
            public void onSuccess(Object res) {
                setToastText("更新成功");
                state.setValue(new Boolean(true));
            }
            @Override
            public void onFailure(OkHttpException failuer) {
                setToastText("更新失败");
                state.setValue(new Boolean(false));
            }
        };
        RequestParams params = new RequestParams();
        params.put("id", user.getId());
        params.put("name", user.getName());
        params.put("age", user.getAge());
        params.put("gender", user.getGender());
        params.put("star", user.getStarsign());
        params.put("city", user.getCity());
        params.put("hobby", user.getHobby());
        params.put("sign", user.getSignature());

        AsynRequestUtil.postMultipart(AppServer.ROOT_PATH + "/home/updateUserInfo", params, images, null, callback);
    }
}
